/*
 * @Author: Oscar Pena
 * 
 * */
package FlowGram.Application.SimulatorWindow.TerrainEditor;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;

public class Wall extends MapObject {
	private Color color;
	private Direction Orientation;
	
	
	public Wall(int x, int y, Direction or){
		//@Description: constructor
		super.setPosition(x, y);		
		setColorBlack();
		Orientation = or;
	}
	public void setColorBlack(){
		//@Description: the color of the walls are turned to black when they are added to the terrain or the terrain is loaded;
		color = Color.BLACK;
	}
	public void setColorRed(){
		//@Description: the color of the wall is turned to red if the Finch collides to it.
		color = Color.RED;
	}

	public boolean equals(Wall w){

		return super.equals(w) && w.color == this.color && w.Orientation == this.Orientation;
	}
	public String toString(){
		//@Description: returns a string of the members of this object
		String ts = "";
		ts = "Wall " + super.toString() + " Color = " + this.color + " Orientation = " + this.Orientation;
		return ts;
	}
	public Direction getOrientation(){
		return this.Orientation;
	}
	public Color getColor(){
		return this.color;
	}
	public void Draw(Graphics2D g2d, int scale){
		g2d.setColor(this.getColor());
		g2d.setStroke(new BasicStroke(3));
		int x, y;
		x = (this.getPositionX() * scale);
		y = (this.getPositionY() * scale);
		if (this.Orientation == Direction.EAST){
			x = x + scale;
			g2d.fillRect(x-2, y, 6, scale+3);
		} else if (this.Orientation == Direction.SOUTH){
			y = y + scale;
			g2d.fillRect(x, y-2, scale+3, 6);
		} else if (this.Orientation == Direction.WEST){
			g2d.fillRect(x-2, y, 6, scale+3);
		} else if (this.Orientation == Direction.NORTH){
			g2d.fillRect(x, y-2, scale+3, 6);
		}
	}
	
	public boolean detectcoll(Finch finch, boolean paint) {
				
				//paint = true;
				boolean a = false;
				if (finch.getOrientation() == Direction.NORTH){
					if(finch.getPositionX() == this.getPositionX() && finch.getPositionY()-1 == this.getPositionY()  && this.Orientation == Direction.SOUTH){
						if(paint== true) {this.setColorRed();}
						a = true;
					}
					if(finch.getPositionX() == this.getPositionX() && finch.getPositionY() == this.getPositionY() && this.Orientation == Direction.NORTH){
						if(paint== true) {this.setColorRed();}
						a = true;
					} 
				} 
				if (finch.getOrientation() == Direction.SOUTH){
					if(finch.getPositionX() == this.getPositionX() && finch.getPositionY()+1 == this.getPositionY()  && this.Orientation == Direction.NORTH){
						if(paint == true) {this.setColorRed();}
						a = true;
					} 
					if(finch.getPositionX() == this.getPositionX() && finch.getPositionY() == this.getPositionY()  && this.Orientation == Direction.SOUTH){
						if(paint == true) {this.setColorRed();}
						a = true;
					} 
				} 
				if (finch.getOrientation() == Direction.EAST ){
					if(finch.getPositionX()+1 == this.getPositionX() && finch.getPositionY() == this.getPositionY()  && this.Orientation == Direction.WEST){
						if(paint == true) {this.setColorRed();}
						a = true;
					} 
					if(finch.getPositionX() == this.getPositionX() && finch.getPositionY() == this.getPositionY()  && this.Orientation == Direction.EAST){
						if(paint == true) {this.setColorRed();}
						a = true;
					} 
				} 
				if (finch.getOrientation() == Direction.WEST){
					if(finch.getPositionX()-1 == this.getPositionX() && finch.getPositionY() == this.getPositionY()  && this.Orientation == Direction.EAST){
						if(paint == true) {this.setColorRed();}
						a = true;
					} 
					if(finch.getPositionX() == this.getPositionX() && finch.getPositionY() == this.getPositionY()  && this.Orientation == Direction.WEST){
						if(paint== true) {this.setColorRed();}
						a = true;
					}
				} 
			return a;
		}
	}
